<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 
        :nth-child(an+b)

        :nth-child(2n) 0 2 4 6 8偶数
        :nth-child(2n+1) 1 3 5 7 9奇数

         */
         .box :nth-child(2n){
            background-color: red;
         }
         .box :nth-child(even){
            background-color: red;
         }
         .box :nth-child(2n+1){
            background-color: blue;
         }
         .box :nth-child(odd){
            background-color: blue;
         }
    </style>
</head>
<body>
        <div class="box">
        <p>p1</p>
        <div>div1</div>
        <p>p2</p>
        <div>div2</div>
        <p>p3</p>
        <div>div3</div>
        <p>p4</p>
        <div>div4</div>
    </div>
</body>
</html>